﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace INSTA.AI97.BankApp.BLL
{
    /// <summary>
    /// Represents a Person
    /// </summary>
    public class Person
    {
        private string  _name;
        private string  _firstName;
        private int     _yearOfBirth;


        #region -- Constructor(s) --

        /// <summary>
        /// Initializes a new instance of 
        /// the <see cref="Person"/> class.
        /// </summary>
        public Person()
            : this(string.Empty, string.Empty, -1)
        { }

        /// <summary>
        /// Initializes a new instance of 
        /// the <see cref="Person"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public Person(string name)
            : this(name, string.Empty, -1)
        { }

        /// <summary>
        /// Initializes a new instance of 
        /// the <see cref="Person"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="firstName">The first name.</param>
        public Person(string name, string firstName)
            : this(name, firstName, -1)
        { }
        

        /// <summary>
        /// Initializes a new instance 
        /// of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="yearOfBirth">The year of birth.</param>
        public Person(string name, string firstName, int yearOfBirth)
        {
            Name            = name;
            FirstName       = firstName;
            YearOfBirth     = yearOfBirth;
        }

        #endregion

        #region -- Properties --



        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <remarks>
        /// Must always be in uppercase.
        /// </remarks>
        public string Name
        {
            get { return _name; }
            set { _name = value.ToUpper(); }
        }

        /// <summary>
        /// Gets or sets the first name.
        /// </summary>
        public string FirstName
        {
            get { return _firstName; }
            set
            {
                // if the pased value exceeds 12 chars.
                if (value.Length > 12)
                {
                    value = value.Substring(0, 12);
                }

                _firstName = value;
            }
        }

        /// <summary>
        /// Gets or sets the year of birth.
        /// </summary>
        public int YearOfBirth
        {
            get { return _yearOfBirth; }
            set
            {
                // Let's get the current year..
                int currentYear = DateTime.Now.Year;

                if (value <= currentYear - 100 || value >= currentYear)
                {
                    value = -1;
                }
                _yearOfBirth = value;
            }
        }

        /// <summary>
        /// Gets the age.
        /// </summary>
        public int Age
        {
            get
            {
                if (_yearOfBirth == -1)
                {
                    return -1;
                }
                else
                {
                    return DateTime.Now.Year - _yearOfBirth;
                }
            }
        }

        #endregion
    }
}
